package com.hellobike.haxing.modules.order.mapper;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import com.hellobike.haxing.modules.order.entity.OrderAftersale;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;

/**
 * @Description: 售后订单
 * @Author: haxing-boot
 * @Date:   2020-02-08
 * @Version: V1.0
 */
public interface OrderAftersaleMapper extends BaseMapper<OrderAftersale> {
    /**
     * 分页查询
     * @param page
     * @param queryWrapper
     * @return
     */
    IPage<OrderAftersale> queryPage(Page<OrderAftersale> page,@Param(Constants.WRAPPER) QueryWrapper<OrderAftersale> queryWrapper);

    /**
     * 查询售后订单明细
     * @param afterId
     * @return
     */
    @Select("select a.*,o.bill_no as \"billNo\",o.pay_amount as \"payAmount\",s.address,s.real_name as \"shopRealName\",u.mobile,u.nickname from t_order_aftersale a,t_order o,t_shop s,t_user u where  a.order_id=o.id and o.shop_id=s.id and o.user_id=u.id and a.id=#{afterId}")
    OrderAftersale getOrderById(Long afterId);

    /**
     * 根据明细ID查询售后成功的售后单
     * @param orderDetailId
     * @return
     */
    @Select("select d.* from t_order_aftersale d ,t_order_aftersale_detail f where d.id=f.order_after_id and f.order_detail_id=#{orderDetailId} and d.deleted=0 and d.after_status=15 limit 1")
    OrderAftersale getAfterSuccess(Long orderDetailId);
}
